// store/index.js
import { createStore } from 'vuex';

// 引入各个模块
//import moduleA from './modules/moduleA';
//import moduleB from './modules/moduleB';

// 创建 Vuex store 实例
export default createStore({
    state: {
        // 可以在这里定义全局状态
        clients_brief_data: {}, // 初始值为空字典
        apps_brief_data: {},
        configs: {},
        auth_message_visiable: false,
    },
    mutations: {
        // 定义修改状态的方法（必须是同步的）
        // 用于更新 clients_brief_data 的方法
        setClientsBriefData(state, payload) {
            state.clients_brief_data = payload;
        },
        // 用于更新单个 client 数据的方法
        setClientBriefValue(state, key, value) {
            state.clients_brief_data[key] = value; // 动态更新字典中的键值对
        },
        // 清空字典的方法
        removeClientBriefKey(state, key) {
            delete state.clients_brief_data[key]; // 动态删除字典中的键值对
        },
        setAppsBriefData(state, payload) {
            state.apps_brief_data = payload;
        },
        setAppsBriefValue(state, key, value) {
            state.apps_brief_data[key] = value;
        },
        removeAppsBriefKey(state, key) {
            delete state.apps_brief_data[key];
        },
        setConfigs(state, payload) {
            state.configs = payload;
        },
        setConfigValue(state, key, value) {
            state.configs[key] = value;
        },
        removeConfigKey(state, key) {
            delete state.configs[key];
        },
        setAuthMessageVisible(state, payload) {
            state.auth_message_visiable = payload;
        }
    },
    actions: {
        // 定义异步操作
        // 异步更新 clients_brief_data 的方法
        // setClientsBriefData({ commit }, data) {
        //     commit('SET_CLIENTS_BRIEF_DATA', data);
        // },
        // setClientBriefValue({ commit }, key, value) {
        //     commit('UPDATE_CLIENT_DATA', key, value);
        // }
    },
    getters: {
        // 定义获取状态的计算属性
        // 返回整个 clients_brief_data
        clientsBriefData: (state) => state.clients_brief_data,
        // 返回特定 client 的数据
        getClientBriefValue: (state) => (key) => state.clients_brief_data[key],
        appsBriefData: (state) => state.apps_brief_data,
        getAppsBriefValue: (state) => (key) => state.apps_brief_data[key],
        configs: (state) => state.configs,
        getConfigValue: (state) => (key) => state.configs[key],
        isAuthMessageVisible: (state) => state.auth_message_visiable
    },
    modules: {
        // 注册模块
        //moduleA,
        //moduleB
    }
});